export default {

    getCookie:function(key)
    {
        var arr,reg = RegExp("(^| )" + key + "=([^;]+)(;|$)");
        if (arr = document.cookie.match(reg))
            return decodeURIComponent(arr[2]);
        else
            return null;
    },



    /**
     * 对话框
     * @param callBack 确定执行的回调函数
     * @param catchBack 取消执行的回调函数
     * @param msg 对话框的内容
     * @param type 对话框类型
     * @param data 对话框按钮和种类属性等对象
     */
    confirm : function (callBack, catchBack, msg, type, data) {
        msg = typeof msg !== 'undefined' ? msg : '是否取消操作？'
        type = typeof type !== 'undefined' ? type : '提示'
        data =
            typeof data !== 'undefined'
                ? data
                : {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }
        typeof callBack !== 'function'
            ? this.$confirm(msg, type, data)
            : typeof catchBack !== 'function'
            ? this.$confirm(msg, type, data).then(callBack)
            : this.$confirm(msg, type, data)
                .then(callBack)
                .catch(catchBack)
    },
     /**
     * 登录成功后本地保存用户的状态
     */
    saveUserState : function (userName, userPhone) {
        userName = typeof userName == 'undefined' ? 'user' : userName
        userPhone = typeof userPhone == 'undefined' ? '0' : userPhone
        var d = new Date()
        d.setTime(d.getTime() + 24 * 60 * 60 * 1000)
        var expires = 'expires=' + d.toUTCString()
        document.cookie = userName + '=' + userPhone + '; '
    },

     /**
     * 获得本地用户登录状态
     * @param {String} userName
     */
    getUserState : function (userName) {
        typeof userName == 'undefined' ? 'user' : userName
        var arr,
            reg = new RegExp('(^| )' + userName + '=([^;]*)(;|$)')
        if ((arr = document.cookie.match(reg))) {
            return arr[2] == '0' ? null : arr[2]
        } else return null
    },

    /**
     * 判断是否是JSON字符串
     * @param str
     * @returns {boolean}
     */
    isJsonString : function (str) {
        try {
            if (typeof JSON.parse(str) == "object") {
                return true;
            }
        } catch (e) {
        }
        return false;
    },

    delCookie : function (name) {
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval = getCookie(name);
        if (cval != null)
            document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
    },

    openMessage:function(msg,typee) {
        this.$message({
          message:msg,
          type: typee
        });
      },




};
